package util.actionListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 实现交互反馈
 * 鼠标移动进入组件时改变颜色，移除时回复颜色
 */
public class MouseEnterAction extends MouseAdapter {
    JButton but=null;  //需要发生动作的组件对象
    JMenu jMenu=null;
    @Override
    public void mouseEntered(MouseEvent e) {
        if (jMenu != null) {
            jMenu.setBackground(Color.cyan);

        }
        if (but != null) {
            but.setBackground(Color.cyan);
        }

    }

    @Override
    public void mouseExited(MouseEvent e) {
        if (but!=null) but.setBackground(null);
        if(jMenu!=null) jMenu.setBackground(null);

    }

    public MouseEnterAction(JButton button) {
        this.but = button;

    }
    public MouseEnterAction(JMenu jMenu) {
        this.jMenu=jMenu;

    }
}
